﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region MixProportionDesignDao

        public List<tb_RPT_OpeningAppraisal> GetAllOpeningAppraisal()
        {
            var query = (from obj in this.tb_RPT_OpeningAppraisals
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }
        public List<tb_RPT_OpeningAppraisal> GetOpeningAppraisalBySequence(string strSequence)
        {

            var query = (from obj in this.tb_RPT_OpeningAppraisals
                         where obj.IsDelete == 0 && obj.Sequence == strSequence
                         select obj).ToList();
            return query;
        }
        public List<tb_RPT_OpeningAppraisal> GetOpeningAppraisalByProjectName(string strProjectName)
        {
            var query = (from obj in this.tb_RPT_OpeningAppraisals
                         where obj.IsDelete == 0 && obj.ProjectName == strProjectName
                         select obj).ToList();
            return query;
        }

        public List<tb_RPT_OpeningAppraisal> GetOpeningAppraisalByContition(string strReportSequence, string strSequence,
                                                                                  string strIDSequence, string strMixingEquipment,
                                                                                  string strProjectName, string strConstructionUnit)
        {
            var tq = from obj in this.tb_RPT_OpeningAppraisals
                     where obj.IsDelete == 0
                     select obj;

            if (strReportSequence.Length > 0)
            {
                tq = tq.Where(entity => entity.ReportSequence == strReportSequence);
            }

            if (strSequence.Length > 0)
            {
                tq = tq.Where(entity => entity.Sequence == strSequence);
            }

            if (strIDSequence.Length > 0)
            {
                tq = tq.Where(entity => entity.IDSequence == strIDSequence);
            }

            if (strMixingEquipment.Length > 0)
            {
                tq = tq.Where(entity => entity.ProjectName == strMixingEquipment);
            }

            if (strProjectName.Length > 0)
            {
                tq = tq.Where(entity => entity.ProjectName == strProjectName);
            }

            if (strConstructionUnit.Length > 0)
            {
                tq = tq.Where(entity => entity.ConstructionUnit == strConstructionUnit);
            } 

            var query = tq.ToList();
            return query;
        }

        public tb_RPT_OpeningAppraisal GetOpeningAppraisalById(int id)
        {
            return this.tb_RPT_OpeningAppraisals.SingleOrDefault(tb_RPT_OpeningAppraisals => tb_RPT_OpeningAppraisals.Id == id);
        }

        public void CreateOpeningAppraisal(tb_RPT_OpeningAppraisal entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_RPT_OpeningAppraisals.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyOpeningAppraisal(tb_RPT_OpeningAppraisal entity)
        {
            tb_RPT_OpeningAppraisal instance = this.tb_RPT_OpeningAppraisals.SingleOrDefault(p => p.Id == entity.Id);
            instance.Sequence = entity.Sequence;
            instance.ReportSequence = entity.ReportSequence;
            instance.IDSequence = entity.IDSequence;
            instance.MixingEquipment = entity.MixingEquipment;
            instance.ProjectName = entity.ProjectName;
            instance.ConstructionUnit = entity.ConstructionUnit;
            instance.StrengthGrade = entity.StrengthGrade;
            instance.MixNumbers = entity.MixNumbers;
            instance.ASHThan = entity.ASHThan;
            instance.Demandslump = entity.Demandslump;
            instance.Testunit = entity.Testunit;
            instance.SandRatio = entity.SandRatio;
            instance.WaterCement1 = entity.WaterCement1;
            instance.Fine1 = entity.Fine1;
            instance.CoarseSand1 = entity.CoarseSand1;
            instance.Stones1 = entity.Stones1;
            instance.Water1 = entity.Water1;
            instance.Admixture1 = entity.Admixture1;
            instance.ASH1 = entity.ASH1;
            instance.ExpansionAgent1 = entity.ExpansionAgent1;
            instance.FineSandWater = entity.FineSandWater;
            instance.CoarseSandWater = entity.CoarseSandWater;
            instance.WaterCement2 = entity.WaterCement2;
            instance.Fine2 = entity.Fine2;
            instance.CoarseSand2 = entity.CoarseSand2;
            instance.Stones2 = entity.Stones2;
            instance.Water2 = entity.Water2;
            instance.Admixture2 = entity.Admixture2;
            instance.ExpansionAgent2 = entity.ExpansionAgent2;
            instance.DESIGNDegreeSlump = entity.DESIGNDegreeSlump;
            instance.DESIGNSpread = entity.DESIGNSpread;
            instance.DESIGNCompressiveStrength = entity.DESIGNCompressiveStrength;
            instance.MEASUSDegreeSlump = entity.MEASUSDegreeSlump;
            instance.MEASUSSpread = entity.MEASUSSpread;
            instance.MEASUSCompressiveStrength = entity.MEASUSCompressiveStrength;
            instance.IsSameAsApply = entity.IsSameAsApply;
            instance.REMARKDegreeSlump = entity.REMARKDegreeSlump;
            instance.REMARKSpread = entity.REMARKSpread;
            instance.REMARKCompressiveStrength = entity.REMARKCompressiveStrength;
            instance.Remark = entity.Remark;
            instance.BuildUnit = entity.BuildUnit;
            instance.ConcreteTestMatchUnit = entity.ConcreteTestMatchUnit;
            instance.UnitHeadTechnology = entity.UnitHeadTechnology;
            instance.MixingUnit = entity.MixingUnit;
            instance.TestDate = entity.TestDate;
              

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;

            this.SubmitChanges();
        }

        public void DeleteOpeningAppraisal(tb_RPT_OpeningAppraisal entity)
        {
            tb_RPT_OpeningAppraisal deleteEntity = tb_RPT_OpeningAppraisals.SingleOrDefault(p => p.Id == entity.Id);
            tb_RPT_OpeningAppraisals.DeleteOnSubmit(deleteEntity);

            this.SubmitChanges();
        }

        #endregion

    }

}
